libgaim framework to r 200, trying to eliminate an ssl crash often seen with TLS...
[adiumx.git] / Other / Adium 1.6 Pref Importer / CBOldPrefsImporterAppController.m
blobf1afeae79284479ee4b54563ae45b1ffdaac431f
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "AIContentController.h"
18 #import "CBOldPrefsImporterAppController.h"
19 #import <AIUtilities/AIUtilities.h>
20 #include <unistd.h>
22 #define ADIUM_1X_LOGS_PATH      @"~/Library/Application Support/Adium/Users"
24 //Stupid Proteus status codes..
25 #define PROTEUS_AWAY_STATUS     7
26 #define PROTEUS_3_STATUS    [[[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Application Support"] stringByAppendingPathComponent:@"Instant Messaging"] stringByAppendingPathComponent:@"Profile"] stringByAppendingPathComponent:@"Status.plist"]
27 #define PROTEUS_4_STATUS    [[[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Application Support"] stringByAppendingPathComponent:@"Proteus"] stringByAppendingPathComponent:@"Profile"] stringByAppendingPathComponent:@"Status.plist"]
31 @interface CBOldPrefsImporterAppController(PRIVATE)
32 - (void)importAliases;
33 - (void)importContacts;
34 @end
36 @implementation CBOldPrefsImporterAppController
38 - (void)awakeFromNib
40     iconDict = [[[NSMutableDictionary alloc] init] retain];
41         [contentController initController];
42     [tabView_ClientTabs selectTabViewItemAtIndex:0];
43     [popUpButton_account removeItemAtIndex:0];
44     [popUpButton_user removeItemAtIndex:0];
45     [progressIndicator setIndeterminate:NO];
46     [progressIndicator setUsesThreadedAnimation:YES];
47         
48         [spinner_ClientProgress setUsesThreadedAnimation:YES];
49         [spinner_ClientProgress setHidden:NO];
50         [spinner_ClientProgress startAnimation:nil];
51         [spinner_ClientProgress display];
52         
53         [popUpButton_Clients setAction:@selector(changeClientSelection:)];
54         [popUpButton_Clients setAutoenablesItems:NO];
55         
56         
57         
58         
59     NSString                            *file;
60     NSString                            *dirPath = [@"~/Library/Application Support/Adium/Users" stringByExpandingTildeInPath];
61     NSDirectoryEnumerator *enumer = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];
62         
63     while((file = [enumer nextObject]))
64         {
65                 [enumer skipDescendents];
66                 if([[[enumer fileAttributes] objectForKey:@"NSFileType"] isEqual:@"NSFileTypeDirectory"])
67                         [popUpButton_account addItemWithTitle:file];
68         }
69         
70     dirPath = [@"~/Library/Application Support/Adium 2.0/Users" stringByExpandingTildeInPath];
71     enumer = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];
72         [popUpButton_user removeAllItems];
73         
74     while((file = [enumer nextObject]))
75         {
76                 [enumer skipDescendents];
77                 if([[[enumer fileAttributes] objectForKey:@"NSFileType"] isEqual:@"NSFileTypeDirectory"])
78                 {
79                         if (![file isEqualToString:@".DS_Store"])
80                         { 
81                                 [popUpButton_user addItemWithTitle:file];
82                         }
83                 }
84         }
85         
86     [window_main makeKeyAndOrderFront:nil];
87         
88         //No Adium 1.x prefs
89         if([popUpButton_account numberOfItems] == 0){
90                 [popUpButton_account setEnabled:NO];
91                 [button_Adium_Logs setEnabled:NO];
92                 [button_Adium_Aliases setEnabled:NO];
93                 [button_Adium_Contacts setEnabled:NO];  
94                 [popUpButton_account addItemWithTitle:@"No Adium 1.x Prefs found."];
95                 [popUpButton_account selectItemWithTitle:@"No Adium 1.x Prefs found."];
96         //NSBeginAlertSheet(@"Nothing to import", @"Quit", nil, nil, window_main, NSApp, @selector(terminate:), nil, nil, @"I cannot find any Adium 1.x preferences to import.");
97         
98         }
99         
100         
101         //No Adium 2.0 prefs
102         if([popUpButton_user numberOfItems] == 0){
103                 NSBeginAlertSheet(@"Run Adium 2 first", @"Quit", nil, nil, window_main, NSApp, @selector(terminate:), nil, nil, @"You must run Adium 2 before any settings can be imported");
104         }
105         
106          
107         //Multiple Adium 2.0 users
108         //if([popUpButton_user numberOfItems] > 1)
109 //      {
110 //              [NSApp beginSheet:theSheet
111 //                 modalForWindow:window_main
112 //                      modalDelegate:self
113 //                 didEndSelector:nil
114 //                        contextInfo:nil];
115 //      }
116         
117         //Here comes the other client stuff yeah yeah yeah!!
118         NSMenuItem  *item;
119         NSImage     *icon;
120         NSString *path;
121         NSString *settingsPath;
122         NSFileManager *manager = [NSFileManager defaultManager];
123         [popUpButton_Clients removeItemAtIndex:0];
124         
125         path = [[NSString alloc]init];
126         path = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"iChat"];
127         [iconDict setObject:[[NSWorkspace sharedWorkspace] iconForFile:path] forKey:@"iChat"];
128         settingsPath = [[NSString stringWithString:@"~/Library/Preferences/com.apple.iChat.plist"] stringByExpandingTildeInPath];
129         
130         [popUpButton_Clients addItemWithTitle:@"iChat"];
131         
132                 item = (NSMenuItem *)[popUpButton_Clients lastItem];
133                 icon = [iconDict objectForKey:[item title]];
134                 [icon setSize:NSMakeSize(16,16)];
135                 [item setImage:icon];
136         if([manager fileExistsAtPath:settingsPath]){
137                 [item setEnabled:YES];
138         }else{
139                 [item setEnabled:NO];
140         }
142         path = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"Proteus"];
143         [iconDict setObject:[[NSWorkspace sharedWorkspace] iconForFile:path] forKey:@"Proteus"];
144         settingsPath = [@"~/Library/Application Support/Proteus/" stringByExpandingTildeInPath];
145         [popUpButton_Clients addItemWithTitle:@"Proteus"];
146                 item = (NSMenuItem *)[popUpButton_Clients lastItem];
147                 icon = [iconDict objectForKey:[item title]];
148                 [icon setSize:NSMakeSize(16,16)];
149                 [item setImage:icon];
150                 if([manager fileExistsAtPath:settingsPath]){
151                         [item setEnabled:YES];
152                 }else{
153                         [item setEnabled:NO];
154                 }
155         
156         path = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"Fire"];
157         [iconDict setObject:[[NSWorkspace sharedWorkspace] iconForFile:path] forKey:@"Fire"];
158         settingsPath = [@"~/Library/Application Support/Fire/" stringByExpandingTildeInPath];
159                 [popUpButton_Clients addItemWithTitle:@"Fire"];
160                 item = (NSMenuItem *)[popUpButton_Clients lastItem];
161                 if ([[NSFileManager defaultManager] fileExistsAtPath:path]){
162                         icon = [iconDict objectForKey:[item title]];
163                 }else{
164                         icon = [NSImage imageNamed:@"ErrorAlert"];
165                 }
166                 [icon setSize:NSMakeSize(16,16)];
167                 
168                 [item setImage:icon];
169                 if([manager fileExistsAtPath:settingsPath]){
170                         [item setEnabled:YES];
171                 }else{
172                         [item setEnabled:NO];
173                 }
175                 [spinner_ClientProgress stopAnimation:nil];
176                 [spinner_ClientProgress setHidden:YES];
179 - (void)dealloc
181         [super dealloc];
182     [contentController closeController];
185 - (NSMutableArray *)_loadAwaysFromArray:(NSArray *)array
187     NSEnumerator        *enumerator;
188     NSDictionary        *dict;
189     NSMutableArray      *mutableArray = [NSMutableArray array];
190     
191     enumerator = [array objectEnumerator];
192     while((dict = [enumerator nextObject])){
193         NSString        *type = [dict objectForKey:@"Type"];
194         
195         if([type isEqualToString:@"Group"]){
196             [mutableArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
197                 @"Group", @"Type",
198                 [self _loadAwaysFromArray:[dict objectForKey:@"Contents"]], @"Contents",
199                 [dict objectForKey:@"Name"], @"Name",
200                 nil]];
201             
202         }else if([type isEqualToString:@"Away"]){
203             NSMutableDictionary     *newDict = [NSMutableDictionary dictionary];
204             NSString                *title = [dict objectForKey:@"Title"];
205             NSData                  *autoresponse = [dict objectForKey:@"Autoresponse"];
206             
207             [newDict setObject:@"Away" forKey:@"Type"];
208             [newDict setObject:[NSAttributedString stringWithData:[dict objectForKey:@"Message"]] forKey:@"Message"];
209             
210             if(title && [title length]){
211                 [newDict setObject:title forKey:@"Title"];
212             }
213             
214             if(autoresponse){
215                 [newDict setObject:[NSAttributedString stringWithData:autoresponse] forKey:@"Autoresponse"];
216             }
217             
218             [mutableArray addObject:newDict];
219         }
220     }
221     return(mutableArray);
224 //Recursively build a savable away message array (replacing NSAttributedString with NSData)
225 - (NSArray *)_saveArrayFromArray:(NSArray *)array
227     NSEnumerator        *enumerator;
228     NSDictionary        *dict;
229     NSMutableArray      *saveArray = [NSMutableArray array];
230     
231     enumerator = [array objectEnumerator];
232     while((dict = [enumerator nextObject])){
233         NSString        *type = [dict objectForKey:@"Type"];
234         
235         if([type isEqualToString:@"Group"]){
236             [saveArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:
237                 @"Group", @"Type",
238                 [self _saveArrayFromArray:[dict objectForKey:@"Contents"]], @"Contents",
239                 [dict objectForKey:@"Name"], @"Name",
240                 nil]];
241             
242         }else if([type isEqualToString:@"Away"]){
243             NSMutableDictionary     *newDict = [NSMutableDictionary dictionary];
244             NSString                *title = [dict objectForKey:@"Title"];
245             NSData                  *autoresponse = [[dict objectForKey:@"Autoresponse"] dataRepresentation];
246             
247             [newDict setObject:@"Away" forKey:@"Type"];
248             [newDict setObject:[[dict objectForKey:@"Message"] dataRepresentation] forKey:@"Message"];
249             
250             if(title && [title length]){
251                 [newDict setObject:title forKey:@"Title"];
252             }
253             
254             if(autoresponse){
255                 [newDict setObject:autoresponse forKey:@"Autoresponse"];
256             }
257             
258             [saveArray addObject:newDict];
259         }
260     }
261     
262     return(saveArray);
265 - (BOOL)ensureAdiumIsClosed
267         NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
268         NSEnumerator*enumerator;
269         NSDictionary*appDict;
270         
271         enumerator = [apps objectEnumerator];
272         while((appDict = [enumerator nextObject])){
273                 if([[appDict objectForKey:@"NSApplicationName"] rangeOfString:@"Adium"].location != NSNotFound &&
274                    [[appDict objectForKey:@"NSApplicationName"] rangeOfString:@"Importer"].location == NSNotFound){
275                         //Alert
276                         NSBeginAlertSheet(@"Adium is running", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Please close all copies of Adium before importing.");
277                         
278                         //Return NO
279                         return(NO);
280                 }
281         }
282         
283         return(YES);
287 - (IBAction)sheetButton:(id)sender
289         [[sender window] orderOut:self];
290         [NSApp endSheet:[sender window] returnCode:YES];
294 - (IBAction)importContacts:(id)sender
296         [NSApp beginSheet:importListSheet
297            modalForWindow:window_main
298                 modalDelegate:self
299            didEndSelector:nil
300                   contextInfo:nil];
304 - (IBAction)importLogs:(id)sender
306         if([self ensureAdiumIsClosed]){
307                 
308                 NSString                *importingFromAccount = [popUpButton_account titleOfSelectedItem];
309                 NSString                *importingForAccount = [popUpButton_user titleOfSelectedItem];
310                 NSString                *newLogFolder;
311                 NSString                *oldUserFolder;
312                 NSString                *oldLogFolder;
313                 NSEnumerator            *logEnumerator;
314                 NSString                *subFolder;
315                 
316                 NSFileManager   *defaultFileManager = [NSFileManager defaultManager];
317                 
318                 //
319                 [progressIndicator setIndeterminate:YES];
320                 [progressIndicator startAnimation:nil];
321                 
322                 //We scan through the log folder, and copy each log as we come across it
323                 oldUserFolder = [ADIUM_1X_LOGS_PATH stringByExpandingTildeInPath];
324                 newLogFolder = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Logs", importingForAccount] stringByExpandingTildeInPath];
325                 
326                 //Do it
327                                         
328                 //For every contact they messaged
329                 oldLogFolder = [[oldUserFolder stringByAppendingPathComponent:importingFromAccount] stringByAppendingPathComponent:@"Logs"];
330                 logEnumerator = [[defaultFileManager directoryContentsAtPath:oldLogFolder] objectEnumerator];
331                 while((subFolder = [logEnumerator nextObject])){
332                         NSString                *subFolderPath;
333                         NSEnumerator    *fileEnumerator;
334                         NSString                *fileName;
335                         
336                         //For every log file they have
337                         subFolderPath = [oldLogFolder stringByAppendingPathComponent:subFolder];
338                         fileEnumerator = [[defaultFileManager directoryContentsAtPath:subFolderPath] objectEnumerator];
339                         while((fileName = [fileEnumerator nextObject])){
340                                 NSString        *newPath = [NSString stringWithFormat:@"%@/AIM.%@/%@", newLogFolder, importingFromAccount, subFolder];
341                                 
342                                 //Update status
343                                 [currentTask setStringValue:[NSString stringWithFormat:@"Copying %@", fileName]];
344                                 [currentTask display];
345                                 [progressIndicator animate:nil];
346                                 [progressIndicator display];
347                                 
348                                 //Copy the file
349                                 [defaultFileManager createDirectoriesForPath:newPath];
350                                 [defaultFileManager copyPath:[subFolderPath stringByAppendingPathComponent:fileName] 
351                                                                           toPath:[newPath stringByAppendingPathComponent:fileName] 
352                                                                          handler:nil];
353                         }
354                 }
355                 
356                 //
357                 [progressIndicator stopAnimation:nil];
358                 [progressIndicator setNeedsDisplay:YES];
359                 [currentTask setStringValue:@"Log import complete."];
360         }
362 - (IBAction)importAliases:(id)sender
364         NSString *importingFromAccount = [popUpButton_account titleOfSelectedItem];
365         NSString *importingForAccount = [popUpButton_user titleOfSelectedItem];
366         
367         if([self ensureAdiumIsClosed]){
368                 //
369                 [progressIndicator setIndeterminate:YES];
370                 [progressIndicator startAnimation:nil];
371                 
372                 //Open the Adium 1.x buddy list
373                 NSString                *path = nil;
374                 NSString                *listAccount = importingFromAccount;
375                 NSDictionary    *buddyList = nil;
376                 // Load the appropriate buddy list
377                 while (buddyList == nil && listAccount != nil) {
378                         path = [[NSString stringWithFormat:@"~/Library/Application Support/Adium/Users/%@/BuddyList.plist", listAccount] stringByExpandingTildeInPath];
379                         buddyList = [NSDictionary dictionaryWithContentsOfFile:path];
380                         
381                         // If this user shares another user's buddy list, get that one.
382                         if ([buddyList objectForKey:@"shareBuddyListWith"] != nil) {
383                                 // Get list sharer
384                                 listAccount = [buddyList objectForKey:@"shareBuddyListWith"];
385                                 
386                                 // Bust endless loops
387                                 if ([listAccount isEqualToString:importingFromAccount]) {
388                                         //Alert
389                                         NSBeginAlertSheet(@"Shared buddy list problem", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"An unforseen problem with buddy lists endlessly sharing each other has occurred.Ê If you do not know the cause, please contact an Adium developer.");
390                                         [currentTask setStringValue:@"Alias import failed."];
391                                         
392                                         listAccount = nil;
393                                 }
394                         }
395                 }
396                 
397                 if (listAccount && buddyList){
398                         //Scan through all the buddies and groups
399                         int                             numGroups = [[buddyList objectForKey:@"numGroups"] intValue];
400                         int                             i,j;
401                         NSFileManager   *defaultFileManager = [NSFileManager defaultManager];
402                         
403                         for(i = 0; i < numGroups; i++){
404                                 NSDictionary *group = [buddyList objectForKey:[NSString stringWithFormat:@"group %d", i]];
405                                 int numContacts = [[group objectForKey:@"numberOfBuddies"] intValue];
406                                 
407                                 for(j = 0; j < numContacts; j++){
408                                         
409                                         NSString        *alias = [group objectForKey:[NSString stringWithFormat:@"alias %d", j]];
410                                         if(alias && ![alias isEqualToString:@""]){
411                                                 NSString                        *screenname;
412                                                 NSString                        *prefPath;
413                                                 NSMutableDictionary *prefDict;
414                                                 
415                                                 screenname = [[[group objectForKey:[NSString stringWithFormat:@"buddy %d", j]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] lowercaseString];
416                                                 
417                                                 //Update our progress display
418                                                 [currentTask setStringValue:[NSString stringWithFormat:@"Importing alias for %@", screenname]];
419                                                 [currentTask display];
420                                                 [progressIndicator animate:nil];
421                                                 [progressIndicator display];
422                                                 
423                                                 //Open the 2.0 object specific preference file for this contact
424                                                 prefPath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/ByObject/AIM.%@.plist", importingForAccount, screenname] stringByExpandingTildeInPath];
425                                                 prefDict = [NSMutableDictionary dictionaryWithContentsOfFile:prefPath];
426                                                 if(!prefDict) prefDict = [NSMutableDictionary dictionary];
427                                                 
428                                                 //Add the alias key to it
429                                                 [prefDict setObject:alias forKey:@"Alias"];
430                                                 
431                                                 //Save our changes
432                                                 [defaultFileManager createDirectoriesForPath:[prefPath stringByDeletingLastPathComponent]];
433                                                 
434                                                 [prefDict writeToFile:prefPath atomically:YES];
435                                         }
436                                 }
437                         }
439                         //
440                         [currentTask setStringValue:@"Alias import complete."];
441                 }
442                 [progressIndicator stopAnimation:nil];
443                 [progressIndicator setNeedsDisplay:YES];
444         }
447 /*- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)code contextInfo:(void *)info
449         if(code)
450         {
451                 [progressIndicator setIndeterminate:YES];
452                 [progressIndicator startAnimation:self];
453                 [button_import setEnabled:NO];
454                 [popUpButton_account setEnabled:NO];
455                 
456                 if([checkBox_contacts state] == NSOnState
457                    && [popUpButton_account selectedItem])
458                 {
459                         [self importContacts];
460                 }
461                 if([checkBox_aliases state] == NSOnState
462                    && [popUpButton_account selectedItem])
463                 {
464                         [self importAliases];
465                 }
466                 
467                 [currentTask setStringValue:@""];
468                 [progressIndicator stopAnimation:nil];
469                 [progressIndicator setIndeterminate:NO];
470                 [button_import setEnabled:YES];
471                 [popUpButton_account setEnabled:YES];
472         }
475 /*- (void)importContacts
477         
480 /*- (void)importAliases;
485 #pragma mark -
486 #pragma mark Other Client Shtuff
488 - (IBAction)importAwayMessages:(id)sender
490     if([self ensureAdiumIsClosed]){
491         NSString *whichClient;
492         whichClient = [popUpButton_Clients titleOfSelectedItem];
493     
494         if(whichClient == @"iChat"){
495             [self importiChatAways];
496         }
497         else if(whichClient == @"Proteus"){
498             [self importProteusAways];
499         }
500         else if(whichClient == @"Fire"){
501             [self importFireAways];
502         }
503     }
506 - (void)importiChatAways
508     [spinner_importProgress setHidden:NO];
509     [spinner_importProgress startAnimation:nil];
510     [spinner_importProgress display];
511     NSAttributedString *newiChatAwayString;
512     NSMutableDictionary *newAdiumAwayDict;
513     NSString *importingForAccount = [NSString stringWithString:[popUpButton_user titleOfSelectedItem]];
514    
515     // Create array of iChat away messages
516     NSString *iChatPath = [NSString stringWithString:[@"~/Library/Preferences/com.apple.iChat.plist" stringByExpandingTildeInPath]];
517     NSDictionary *iChatDict = [NSDictionary dictionaryWithContentsOfFile:iChatPath];
518     NSArray *iChatMessageArray = [iChatDict objectForKey:@"CustomAwayMessages"];
519         
520     // Create an array of Adium's away messages
521     NSString *awayMessagePath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Away Messages.plist", importingForAccount] stringByExpandingTildeInPath];
522     NSMutableDictionary *adiumDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:awayMessagePath];
523             
524     NSArray *tempArray = [NSArray arrayWithArray:[adiumDictionary objectForKey:@"Saved Away Messages"]];
525     NSMutableArray *AdiumMessageArray = [[self _loadAwaysFromArray:tempArray] retain];
526     // Or, create a blank list if we've never saved one before
527     if (AdiumMessageArray == nil)
528         AdiumMessageArray = [NSMutableArray array];
529     
530         
531     // Loop through each iChat away message
532     NSEnumerator *iChatEnumerator = [iChatMessageArray objectEnumerator];
533     NSEnumerator *AdiumEnumerator = NULL;
534     NSDictionary *AdiumMessage; 
535     NSString *iChatMsgTitle, *iChatMsgContent;
536     NSString *AdiumMsgTitle, *AdiumMsgContent;
537     BOOL messageAlreadyExists;
538         
539     while((iChatMsgContent = [iChatEnumerator nextObject]))
540         {
541             
542             // Create a title for the message by truncating it
543             iChatMsgTitle = [iChatMsgContent stringWithEllipsisByTruncatingToLength:25];
544             
545             // Loop through each Adium away message and compare it to the current iChat message
546             AdiumEnumerator = [AdiumMessageArray objectEnumerator];
547             messageAlreadyExists = NO;
548             
549             while((AdiumMessage = [AdiumEnumerator nextObject]))
550             {
551                 AdiumMsgTitle = [AdiumMessage objectForKey:@"Title"];
552                 AdiumMsgContent = [AdiumMessage objectForKey:@"Message"];
553                 
554                 // If either the title or the content matches, we assume it's already been imported...
555                 if ( AdiumMessage && ([AdiumMsgTitle isEqualToString:iChatMsgTitle] || [AdiumMsgContent isEqual:iChatMsgContent])) {
556                     messageAlreadyExists = YES;
557                     break;
558                 }
559             }
560             
561             // If the message isn't already in Adium's list, add it
562             if (!messageAlreadyExists) {
563                 
564                 // Casting like a drunk fisherman...
565                 newiChatAwayString = [[[NSAttributedString alloc] initWithString:iChatMsgContent 
566                                                                  attributes:[[self contentController] defaultFormattingAttributes]] autorelease];
567                 
568                 // Add the away message to the array... hallelujah!
569                 
570                 newAdiumAwayDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Away",@"Type",newiChatAwayString,@"Message", iChatMsgTitle, @"Title", nil];
571                 
572                 
573                 [AdiumMessageArray addObject:newAdiumAwayDict];
574             }
575         }
576     NSArray *finalArray = [self _saveArrayFromArray:AdiumMessageArray];
577     [adiumDictionary setObject:finalArray forKey:@"Saved Away Messages"];
578     NSDictionary *finalDict = [NSDictionary dictionaryWithDictionary:adiumDictionary];
579     [spinner_importProgress stopAnimation:nil];
580     [spinner_importProgress setHidden:YES];
581         
582     if([finalDict writeToFile:[awayMessagePath stringByExpandingTildeInPath] atomically:YES])
583     {
584         NSBeginAlertSheet(@"iChat messages imported successfully.", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Your iChat away messages have been imported and are now available in Adium.");
585     }
586     else
587     {
588         NSBeginAlertSheet(@"Import failed", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"The import process has encountered an error. Please make sure your permissions are set correctly and try again. If you continue to have problems, please contact an Adium developer.");
589     }
590         
591     
594 - (void)importProteusAways
596     [spinner_importProgress setHidden:NO];
597     [spinner_importProgress startAnimation:nil];
598     [spinner_importProgress display];
599     NSAttributedString *newAwayString;
600     NSMutableDictionary *newAwayDict;
601     NSFileManager *manager;
602     NSString *proteusPath;
603     NSString *importingForAccount = [NSString stringWithString:[popUpButton_user titleOfSelectedItem]];
604     
605     //Create an array of Proteus Away Messages
606     manager  = [[NSFileManager alloc] init];
607     if([manager fileExistsAtPath:PROTEUS_3_STATUS])
608         proteusPath = PROTEUS_3_STATUS;
609     else
610         proteusPath = PROTEUS_4_STATUS;
611     
612     NSDictionary *proteusDict = [NSDictionary dictionaryWithContentsOfFile:proteusPath];
613     NSArray *proteusMessageArray = [proteusDict objectForKey:@"Custom Status Modes"];
614     
615     
616     // Create an array of Adium's away messages
617     NSString *awayMessagePath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Away Messages.plist", importingForAccount] stringByExpandingTildeInPath];
618     NSMutableDictionary *adiumDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:awayMessagePath];
619     NSArray *tempArray = [NSArray arrayWithArray:[adiumDictionary objectForKey:@"Saved Away Messages"]];
620     NSMutableArray *AdiumMessageArray = [[self _loadAwaysFromArray:tempArray] retain];
621     // Or, create a blank list if we've never saved one before
622     if (AdiumMessageArray == nil)
623         AdiumMessageArray = [NSMutableArray array];
624     
625     // Loop through each Proteus away message    
626     NSEnumerator *AdiumEnumerator = NULL;
627     NSDictionary *AdiumMessage; 
628     NSDictionary *proteusMessage/*, *proteusCurrentMessage*/;
629     NSString *AdiumMsgTitle, *AdiumMsgContent;
630     NSString *proteusMsgTitle, *proteusMsgContent;
631     BOOL messageAlreadyExists;
632 //    BOOL importAllStatus;
633     
634             
635     
636     
637     
638     //Get us an array of all the keys in the dictionary
639         
640     NSEnumerator *proteusEnumerator = [proteusMessageArray objectEnumerator];
641     while((proteusMessage = [proteusEnumerator nextObject]))
642     {
643         
644         proteusMsgTitle = [proteusMessage objectForKey:@"Name"];
645         proteusMsgContent = [proteusMessage objectForKey:@"Message"];
646         NSLog(proteusMsgTitle);
647         NSLog(proteusMsgContent);
648         
649         //If we want to import ALL of the messages and not just ones for the away status...
650         if([button_importAllProteusAways state] == NSOnState){
651         
652             
653         // Loop through each Adium away message and compare it to the current proteus message
654         AdiumEnumerator = [AdiumMessageArray objectEnumerator];
655         messageAlreadyExists = NO;
656         
657         while((AdiumMessage = [AdiumEnumerator nextObject]))
658         {
659             // If either the title or the content matches, we assume it's already been imported...
660             AdiumMsgTitle = [AdiumMessage objectForKey:@"Title"];
661             AdiumMsgContent = [AdiumMessage objectForKey:@"Message"];
662             
663             if ( AdiumMessage && ([AdiumMsgTitle isEqualToString:proteusMsgTitle] || [AdiumMsgContent isEqual:proteusMsgContent])) {
664                 messageAlreadyExists = YES;
665                 break;
666             }
667         }
668         // If the message isn't already in Adium's list, add it
669         if (!messageAlreadyExists) 
670         {
671             
672             // Casting like a drunk fisherman...
673             newAwayString = [[[NSAttributedString alloc] initWithString:proteusMsgContent 
674                                                              attributes:[[self contentController] defaultFormattingAttributes]] autorelease];
675             
676             // Add the away message to the array... hallelujah!
677             
678             newAwayDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Away",@"Type",newAwayString,@"Message", proteusMsgTitle, @"Title", nil];
679             
680             
681             [AdiumMessageArray addObject:newAwayDict];
682         }
683         
684         }
685     }        
686         
687     NSArray *finalArray = [self _saveArrayFromArray:AdiumMessageArray];
688     [adiumDictionary setObject:finalArray forKey:@"Saved Away Messages"];
689     NSDictionary *finalDict = [NSDictionary dictionaryWithDictionary:adiumDictionary];
690     [spinner_importProgress stopAnimation:nil];
691     [spinner_importProgress setHidden:YES];
692     
693     if([finalDict writeToFile:[awayMessagePath stringByExpandingTildeInPath] atomically:YES])
694     {
695         NSBeginAlertSheet(@"Proteus messages imported successfully.", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Your Proteus away messages have been imported and are now available in Adium.");
696     }
697     else
698     {
699         NSBeginAlertSheet(@"Import failed", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"The import process has encountered an error. Please make sure your permissions are set correctly and try again. If you continue to have problems, please contact an Adium developer.");
700     }
701     
702         
703     
706 - (void)importFireAways
708     [spinner_importProgress setHidden:NO];
709     [spinner_importProgress startAnimation:nil];
710     [spinner_importProgress display];
711     NSAttributedString *newAwayString;
712     NSMutableDictionary *newAwayDict;
713     NSString *importingForAccount = [NSString stringWithString:[popUpButton_user titleOfSelectedItem]];
714     
715     //Create an array of Fire Away Messages
716     NSString *firePath = [NSString stringWithString:[@"~/Library/Application Support/Fire/FireConfiguration.plist" stringByExpandingTildeInPath]];
717        
718     NSDictionary *fireDict = [NSDictionary dictionaryWithContentsOfFile:firePath];
719     NSDictionary *fireMessageDict = [fireDict objectForKey:@"awayMessages"];
720     
721     
722     // Create an array of Adium's away messages
723     NSString *awayMessagePath = [[NSString stringWithFormat:@"~/Library/Application Support/Adium 2.0/Users/%@/Away Messages.plist", importingForAccount] stringByExpandingTildeInPath];
724     NSMutableDictionary *adiumDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:awayMessagePath];
725     NSArray *tempArray = [NSArray arrayWithArray:[adiumDictionary objectForKey:@"Saved Away Messages"]];
726     NSMutableArray *AdiumMessageArray = [[self _loadAwaysFromArray:tempArray] retain];
727     // Or, create a blank list if we've never saved one before
728     if (AdiumMessageArray == nil)
729         AdiumMessageArray = [NSMutableArray array];
730     
731     
732     // Loop through each Fire away message    
733     NSEnumerator *AdiumEnumerator = NULL;
734     NSDictionary *AdiumMessage; 
735     NSDictionary *fireMessage;
736     NSString *AdiumMsgTitle, *AdiumMsgContent;
737     NSString *fireMsgTitle, *fireMsgContent;
738     BOOL messageAlreadyExists;
739     
740     //Get us an array of all the keys in the dictionary
741     NSArray *fireKeyArray = [[[NSArray alloc] initWithArray:[fireMessageDict allKeys]] autorelease];
742               
743     NSEnumerator *fireEnumerator = [fireKeyArray objectEnumerator];
744     while((fireMsgTitle = [fireEnumerator nextObject]))
745     {
746         fireMessage = [fireMessageDict objectForKey:fireMsgTitle];
747         
748         fireMsgContent = [fireMessage objectForKey:@"message"];
749         NSLog(fireMsgTitle);
750         NSLog(fireMsgContent);
751         
752         // Loop through each Adium away message and compare it to the current Fire message
753         AdiumEnumerator = [AdiumMessageArray objectEnumerator];
754         messageAlreadyExists = NO;
755         
756         while((AdiumMessage = [AdiumEnumerator nextObject]))
757         {
758             // If either the title or the content matches, we assume it's already been imported...
759             AdiumMsgTitle = [AdiumMessage objectForKey:@"Title"];
760             AdiumMsgContent = [AdiumMessage objectForKey:@"Message"];
761             
762             if ( AdiumMessage && ([AdiumMsgTitle isEqualToString:fireMsgTitle] || [AdiumMsgContent isEqual:fireMsgContent])) {
763                 messageAlreadyExists = YES;
764                 break;
765             }
766         }
767         
768         
769         // If the message isn't already in Adium's list, add it
770         if (!messageAlreadyExists) 
771         {
772             
773             // Casting like a drunk fisherman...
774             newAwayString = [[[NSAttributedString alloc] initWithString:fireMsgContent 
775                                                              attributes:[[self contentController] defaultFormattingAttributes]] autorelease];
776             
777             // Add the away message to the array... hallelujah!
778             
779             newAwayDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Away",@"Type",newAwayString,@"Message", fireMsgTitle, @"Title", nil];
780             
781             
782             [AdiumMessageArray addObject:newAwayDict];
783         }
784         
785     }
786     NSArray *finalArray = [self _saveArrayFromArray:AdiumMessageArray];
787     [adiumDictionary setObject:finalArray forKey:@"Saved Away Messages"];
788     NSDictionary *finalDict = [NSDictionary dictionaryWithDictionary:adiumDictionary];
789     [spinner_importProgress stopAnimation:nil];
790     [spinner_importProgress setHidden:YES];
791     
792     if([finalDict writeToFile:[awayMessagePath stringByExpandingTildeInPath] atomically:YES])
793     {
794         NSBeginAlertSheet(@"Fire messages imported successfully.", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"Your Fire away messages have been imported and are now available in Adium.");
795     }
796     else
797     {
798         NSBeginAlertSheet(@"Import failed", @"OK", nil, nil, window_main, nil, nil, nil, nil, @"The import process has encountered an error. Please make sure your permissions are set correctly and try again. If you continue to have problems, please contact an Adium developer.");
799     }
800   }
802     
803     
804     
806 #pragma mark -
807 #pragma mark Application Delegate Methods & Other Ugly Stuff(tm)
809 - (IBAction)changeClientSelection:(id)sender
811         [tabView_ClientTabs selectTabViewItemWithIdentifier:[popUpButton_Clients titleOfSelectedItem]];;
814 - (AIContentController *)contentController
816     return(contentController);
819 - (void)applicationDidFinishLaunching: (NSNotification *)aNotification
821     
824 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
826         return YES;
829 @end